<?php

namespace app\interfaces\model;

use app\interfaces\model\MemberCoupon as MemberCouponModel;
use think\Model;
use think\Request;

class Coupon extends Model
{
    // 开始时间
    protected function getStartTimeAttr($value, $data)
    {
        return date('Y-m-d', $data['start_time']);
    }

    // 结束时间
    protected function getEndTimeAttr($value, $data)
    {
        return date('Y-m-d', $data['end_time']);
    }

    // 领取状态
    protected function getReceiveStatusAttr($value, $data)
    {
        $id = MemberCouponModel::where(['coupon_id' => $data['id'], 'member_id' => Request::instance()->param('user_id')])->value('id');

        return $id ? '1' : '2';
    }
}